<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="../vue.js"></script>
    <style>
      * {
        margin: 0;
        padding: 0;
        list-style: none;
      }

      .oul {
        display: flex;
        text-align: center;
        line-height: 46px;
      }

      .oul > li {
        flex: 1;
      }

      .box {
        text-align: center;
        line-height: 200px;
      }

      .active {
        background: rgb(7, 7, 149);
        color: #fff;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <my-tab :indexs="1" :arr="list"></my-tab>
    </div>
    <!-- 自定义tab组件 -->
    <template id="tab">
      <div>
        <ul class="oul">
          <li
            :class="{active:index === count}"
            v-for="(item,index) in arr"
            @click="changeCount(index)"
          >
            {{item.title}}
          </li>
        </ul>
        <div class="box">{{arr[count].text}}</div>
      </div>
    </template>
    <script>
      // tab组件
      const Tab = {
        template: "#tab",
        // 子组件通过使用属性props接收
        props: {
          arr: {
            /* 对象类型：可以设置数据默认值和类型 */
            type: Array,
            //required:true,//是否必传
            default: () => {
              return [
                {
                  title: "默认",
                  text: "默认的内容",
                },
              ];
            },
          },
          indexs: {
            type: Number,
          },
        },
        data() {
          return {
            count: this.indexs,
          };
        },
        methods: {
          changeCount(index) {
            this.count = index;
          },
        },
      };
      new Vue({
        el: "#app",
        components: {
          "my-tab": Tab,
        },

        data: {
          list: [
            {
              title: "评论管理",
              text: `<input type="text">`,
            },
            {
              title: "发布评论",
              text: "评论内容",
            },
          ],
        },
      });
    </script>
  </body>
</html>
